﻿using Common;
using Network.UpdateData;
using System;
using System.Net.Sockets;

namespace SFJDService.SocketHandle
{
    /// <summary>
    /// 发送广播拉取data数据
    /// </summary>
    public class PH01GetData : PacketHandle
    {
        /// <summary>
        /// UDP, code 1010
        /// </summary>
        /// <param name="socket"></param>
        /// <param name="packet"></param>
        public PH01GetData(Socket socket, Packet packet) : base(socket, packet) { }

        protected override void Handle()
        {
            ClassData dat = new ClassData();
            if (Message == "0")
            {
                dat.Clone(Runtime.xmlData.GetLastData());
            }
            else
            {
                string[] buff = this.Message.Split('♠');
                dat.Clone(Runtime.xmlData.GetDataByID(DateTime.Now.Year.ToString(), Int32.Parse(buff[0])));
            }
            if (!dat.IsEmpty())
            {
                Launcher.SendMsg2All(typeof(PH01GotData).GetDictianaryKey(), dat.CodingToString());
            }
            else
            {
                Launcher.SendMsg2All(typeof(PH01GotData).GetDictianaryKey(), "0");
            }
        }
    }
}
